package com.party.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.party.domain.Collect;
import com.party.domain.Custom;
import com.party.domain.OrderDetail;
import com.party.domain.Orders;

@Mapper
public interface ShoppingMapper 
{
	//增
	
	//添加订单
	@Insert("INSERT INTO Orders(oid,user_id,order_number,order_time,is_state) VALUES(#{oid},#{user_id},#{order_number},#{order_time},#{is_state})")
	@Options(useGeneratedKeys=true, keyProperty="oid")
	void insterOrders(Orders orders);
	
	//添加订单详情
	@Insert("INSERT INTO OrderDetail(odid,orders_id,product_id,product_number) VALUES(#{odid},#{orders_id},#{product_id},#{product_number})")
	void insterOrderDetail(OrderDetail ordersde);
	
	//增加商品收藏
	@Insert("INSERT INTO Collect(coid,user_id,product_id) VALUES(#{coid},#{user_id},#{product_id})")

	void insterCollect(Collect collect);
	
	//添加定制服务
	@Insert("INSERT INTO Custom(cuid,cu_uid,cu_type,cu_area,cu_time,cu_people_number,cu_user,cu_phone,cu_remark) VALUES(#{cuid},#{cu_uid},#{cu_type},#{cu_area},#{cu_time},#{cu_people_number},#{cu_user},#{cu_phone},#{cu_remark})")
	void insterCustom(Custom custom);
	
	//删

	//订单id删除订单
	@Delete("DELETE FROM Orders WHERE oid=#{oid}")
	void deleteOrders(int oid);
	
	//订单id删除订单详情
	@Delete("DELETE FROM OrderDetail WHERE orders_id=#{oid}")
	void deleteOrderDetail(int oid);
	
	//收藏id删除商品收藏
	@Delete("DELETE FROM Collect WHERE coid=#{coid}")
	void deleteCollect(int coid);
	
	//定制id删除定制服务
	@Delete("DELETE FROM Custom WHERE cuid=#{cuid}")
	void deleteCustoms(int cuid);
	
	//查
	
	//订单id查询订单
	@Select("SELECT * FROM Orders WHERE oid = #{oid}")
	Orders selectIdOrders(int oid);
	//订单id查询订单详情
	@Select("SELECT * FROM OrderDetail WHERE orders_id = #{oid}")
	OrderDetail selectIdOrderDetail(int oid);
	
	

	//查询用户所有收藏商品
	@Select("SELECT * FROM Collect  WHERE user_id = #{uid}")
	List<Collect> selectAllCollect(int uid);
	

	//收藏id查询商品收藏
	@Select("SELECT * FROM Collect WHERE coid = #{coid}")
	Collect selectIdCollect(int coid);
	
	//定制id查询定制服务
	@Select("SELECT * FROM Custom WHERE cuid= #{cuid}")
	Custom selectIdCustom(int cuid);
	
	//查询所有定制服务 倒序
	@Select("SELECT * FROM Custom  c ORDER BY c.cuid DESC LIMIT #{start},#{size}")
	List<Custom> selectAllCustom(@Param("start")int start,@Param("size")int size);
	
	//按手机号查询所有定制服务
	@Select("SELECT * FROM Custom c WHERE c.cu_phone=#{phone} ORDER BY c.cuid DESC LIMIT #{start},#{size}")
	List<Custom> selectPhoneCustom(@Param("phone")String phone,@Param("start")int start,@Param("size")int size);
	
	public Collect findById(int coid);
	
	public List<Collect> findByIdCollect(@Param("uid")int uid,@Param("start")int start,@Param("size")int size);
	
	
	public List<Orders> findByIdOrders(@Param("uid")int uid,@Param("start")int start,@Param("size")int size);
	
	public Orders findByOId(int oid);
	
	//查询用户所有未支付订单
	public List<Orders> findByNoStateOrder(@Param("uid")int uid,@Param("start")int start,@Param("size")int size);
	
}
